package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Stocklist;
import com.ruoyi.system.service.IStocklistService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 股票列Controller
 * 
 * @author ruoyi
 * @date 2021-12-26
 */
@Controller
@RequestMapping("/system/stocklist")
public class StocklistController extends BaseController
{
    private String prefix = "system/stocklist";

    @Autowired
    private IStocklistService stocklistService;

    @RequiresPermissions("system:stocklist:view")
    @GetMapping()
    public String stocklist()
    {
        return prefix + "/stocklist";
    }

    /**
     * 查询股票列列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Stocklist stocklist)
    {
        startPage();
        List<Stocklist> list = stocklistService.selectStocklistList(stocklist);
        return getDataTable(list);
    }

    @RequestMapping("/list1")
    @ResponseBody
    public List<Stocklist> list1(Stocklist stocklist)
    {
        List<Stocklist> list = stocklistService.selectStocklistList(stocklist);
        return list;
    }

    /**
     * 导出股票列列表
     */
    @RequiresPermissions("system:stocklist:export")
    @Log(title = "股票列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Stocklist stocklist)
    {
        List<Stocklist> list = stocklistService.selectStocklistList(stocklist);
        ExcelUtil<Stocklist> util = new ExcelUtil<Stocklist>(Stocklist.class);
        return util.exportExcel(list, "股票列数据");
    }

    /**
     * 新增股票列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存股票列
     */
    @RequiresPermissions("system:stocklist:add")
    @Log(title = "股票列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Stocklist stocklist)
    {
        return toAjax(stocklistService.insertStocklist(stocklist));
    }

    /**
     * 修改股票列
     */
    @RequiresPermissions("system:stocklist:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Stocklist stocklist = stocklistService.selectStocklistById(id);
        mmap.put("stocklist", stocklist);
        return prefix + "/edit";
    }

    /**
     * 修改保存股票列
     */
    @RequiresPermissions("system:stocklist:edit")
    @Log(title = "股票列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Stocklist stocklist)
    {
        return toAjax(stocklistService.updateStocklist(stocklist));
    }

    /**
     * 删除股票列
     */
    @RequiresPermissions("system:stocklist:remove")
    @Log(title = "股票列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stocklistService.deleteStocklistByIds(ids));
    }
}
